package com.zzyl.nursing.controller.member;

import java.util.List;

import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.dto.ElderToMemberDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.vo.DeviceDataListByDayAndWeekVo;
import com.zzyl.nursing.vo.DeviceShadowDataVo;
import com.zzyl.nursing.vo.LoginVo;
import com.zzyl.nursing.vo.MemberFamilyDeviceVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.nursing.service.IFamilyMemberService;

/**
 * 老人家属Controller
 * 
 * @author laoYe
 * @date 2025-10-27
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属相关接口")
public class FamilyMemberController extends BaseController {
    @Autowired
    private IFamilyMemberService familyMemberService;

    /**
     * 登录
     * @param dto
     * @return
     * */
    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public R login(@RequestBody UserLoginRequestDto dto){
        LoginVo vo = familyMemberService.login(dto);
        return R.ok(vo);
    }

    /**
     * 查询家人列表
     */
    @GetMapping("/my")
    @ApiOperation("查询家人列表")
    public R queryMemberElderList(){
        List<MemberFamilyDeviceVo> list = familyMemberService.queryMemberElderList();
        return R.ok(list);
    }

    /**
     * 查看已绑定家人列表（分页查询）
     */

    @GetMapping("/list-by-page")
    @ApiOperation("查看已绑定家人列表（分页查询）")
    public R queryMemberElderPage(@RequestParam(defaultValue = "1") Integer pageNum,
                                                                     @RequestParam(defaultValue = "10") Integer pageSize){
        List<MemberFamilyDeviceVo> memberFamilyDeviceVos = familyMemberService.queryMemberElderPage(pageNum, pageSize);
        return R.ok(memberFamilyDeviceVos);
    }

    /**
     * 绑定家人
     */
    @PostMapping("/add")
    @ApiOperation("绑定家人")
    public R add(@RequestBody ElderToMemberDto dto){
        familyMemberService.add(dto);
        return R.ok();
    }

    /**
     * 查询健康数据
     */
    @GetMapping("/queryServiceProperties/{iotId}")
    @ApiOperation("查询健康数据")
    public R queryServiceProperties(@PathVariable String iotId){
        List<DeviceShadowDataVo> list = familyMemberService.queryServiceProperties(iotId);
        return R.ok(list);
    }


    /**
     * 按天统计查询指标数据
     */
    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation("按天统计查询指标数据")
    public R queryDeviceDataListByDay(@RequestParam String iotId,
                                      @RequestParam String functionId,
                                      @RequestParam Long startTime,
                                      @RequestParam Long endTime){
        List<DeviceDataListByDayAndWeekVo> list =familyMemberService.queryDeviceDataListByDay(iotId, functionId, startTime, endTime);
        return R.ok(list);
    }

    /**
     * 按周统计查询指标数据
     */
    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation("按周统计查询指标数据")
    public R queryDeviceDataListByWeek(@RequestParam String iotId,
                                       @RequestParam String functionId,
                                       @RequestParam Long startTime,
                                       @RequestParam Long endTime){
        List<DeviceDataListByDayAndWeekVo> list =familyMemberService.queryDeviceDataListByWeek(iotId, functionId, startTime, endTime);
        return R.ok(list);
    }

}
